package cn.stylefeng.guns.controller.controller;

import cn.stylefeng.guns.controller.model.WebPage;
import cn.stylefeng.guns.modular.system.model.Person;
import cn.stylefeng.guns.modular.system.service.impl.PersonServiceImpl;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;


@Controller
@CrossOrigin
public class Dishonesty {

    private final
    PersonServiceImpl personService;

    @Autowired
    public Dishonesty(PersonServiceImpl personService) {
        this.personService = personService;
    }

    /**
     *
     * @param region 区域
     * @param webpage 接受的基本分页信息
     * @return
     */
    @RequestMapping(value = "/{region:^DL|PS$}/dishonesty/page")
    @ResponseBody
    public Page<Person> dlPerson(@PathVariable(value = "region",required = false) String region,
                                 @RequestBody WebPage webpage) {
        EntityWrapper<Person> entityWrapper = new EntityWrapper<>();
        Wrapper<Person> wrapper;
        wrapper = entityWrapper
                .where("(name like '%"+webpage.getSerach()+"%' or case_number like '%"+webpage.getSerach()+"%' or identification_number like '%"+webpage.getSerach()+"%'" +
                        " or age like '%"+webpage.getSerach()+"%' or address like '%"+webpage.getSerach()+"%' or outstanding_amount like '%"+webpage.getSerach()+"%' or img_url like '%"+webpage.getSerach()+"%') and region = '"+region+"'");
        Page<Person> page = new Page<>(webpage.getCurrent(),webpage.getSize());
        return personService.selectPage(page,wrapper);
    }
}
